import { Switch, Redirect, Route } from "react-router-dom";
import React from "react";
import BeforeEach from "./BeforeEach";

function RouterView(props) {
  const { routes } = props;
  return (
    <Switch>
      {routes.length &&
        routes.map((item, idx) => {
          return item.path ? (
            <Route
              key={item.path}
              path={item.path}
              render={(props) => <BeforeEach {...props} {...item} />}
            />
          ) : (
            <Redirect key={item.to} exact {...item} />
          );
        })}{" "}
    </Switch>
  );
}

export default RouterView;
